package com.mdl.springmvc.task;

import com.mdl.springmvc.task.processor.AbstrucBaseProcessor;
import com.mdl.springmvc.task.processor.Step1Processor;
import com.mdl.springmvc.task.processor.Step2Processor;
import com.mdl.springmvc.task.processor.Step3Processor;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;


/**
 * @Desc
 * @Author madengling
 * @Time 2020/10/28 15:43
 */
@Component
@PropertySource(value = "classpath:config.properties")
public class TaskProcess {
    private static Logger logger = Logger.getLogger(TaskProcess.class);
    @Autowired
    private Step1Processor step1Processor;
    @Autowired
    private Step2Processor step2Processor;
    @Autowired
    private Step3Processor step3Processor;

//    @Scheduled(cron = "${time_min}")
    public void processTask() {
        logger.info("每隔15秒执行一次：" + new Date());
        logger.info("TaskProcess start..");
        boolean stop = true;
        Integer step = 1;
        switch (step){
            case 1:
                logger.info("当前步骤：" + step + ".文件解析，开始执行...");
                stop = doProcess(step1Processor,step);
                if (stop) {
                    break;
                }
                logger.info("文件解析完成！");
            case 2:
                logger.info("当前步骤：" + step + ".数据转换【基础信息】，开始执行...");
                stop = doProcess(step2Processor,step);
                if (stop) {
                    break;
                }
                logger.info("数据转换【基础信息】完成！");
            case 3:
                logger.info("当前步骤：" + step + ".数据转换【资格审批】，开始执行...");
                stop = doProcess(step3Processor,step);
                if (stop) {
                    break;
                }
                logger.info("数据转换【资格审批】完成！");
            default:
                logger.error("未能找到对应的步骤 step:"+step);
        }
    }

    private boolean doProcess(AbstrucBaseProcessor processor, Integer step){
        Boolean isOk = processor.processMain();
        return isOk;
    }

}
